//
//  OfferTableViewCell.m
//  bondwatch_purecode
//
//  Created by Jason Yuan on 10/28/15.
//  Copyright © 2015 Sumridge. All rights reserved.
//

#import "OfferTableViewCell.h"

@implementation OfferTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        offerLabel = [[UILabel alloc] init];
        offerLabel.textAlignment = NSTextAlignmentLeft;
        offerLabel.font = ARIAL10;
        ytwLabel = [[UILabel alloc] init];
        ytwLabel.textAlignment = NSTextAlignmentRight;
        ytwLabel.font = ARIAL10;
        spreadLabel = [[UILabel alloc] init];
        spreadLabel.textAlignment = NSTextAlignmentRight;
        spreadLabel.font = ARIAL10;
        
        [self addSubview:offerLabel];
        [self addSubview:ytwLabel];
        [self addSubview:spreadLabel];
    }
    return self;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setUIFrame {
    if ([UIApplication sharedApplication].statusBarOrientation == UIDeviceOrientationLandscapeLeft ||
        [UIApplication sharedApplication].statusBarOrientation == UIDeviceOrientationLandscapeRight) {
        
    } else {
        [offerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(5);
            make.centerY.equalTo(self);
            make.width.mas_equalTo(80);
        }];
        
        [spreadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-5);
            make.centerY.equalTo(self);
            make.width.mas_equalTo(40);
        }];
        
        [ytwLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(spreadLabel.mas_left).offset(-5);
            make.centerY.equalTo(self);
            make.width.mas_equalTo(30);
        }];
    }
}

- (void)setLabelText:(NSDictionary *)offerData {
    NSNumber *offerQty = [offerData objectForKey:@"qty"];
    NSNumber *offerPrice = [offerData objectForKey:@"price"];
    NSString *offer = [NSString stringWithFormat:@"%@M@%.3f", offerQty, [offerPrice floatValue]];
    [offerLabel setText:offer];
    
    NSNumber *yield = [offerData objectForKey:@"yield"];
    [ytwLabel setText:[NSString stringWithFormat:@"%.3f", [yield floatValue]]];
    
    NSNumber *spread = [offerData objectForKey:@"spread"];
    [spreadLabel setText:[NSString stringWithFormat:@"%.1f", [spread floatValue]]];
}

@end
